package com.ykdl.app.login;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.androidquery.AQuery;
import com.ykdl.app.R;
import com.ykdl.app.Utils.PhoneNumberUtils;
import com.ykdl.app.base.BaseActivity;
import com.ykdl.app.main.MainActivity;

public class ForgetPwdActivity extends BaseActivity implements OnClickListener {

	private Button next;
	private TextView sen_bt;
	private AQuery mAQ;
	private String phonnNumber = "";
	private EditText et_phone;
	private PhoneNumberUtils mContentUtils;
	private MyCount mc;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		SetContentLayout(R.layout.activity_forget);
		initTitle("忘记密码");
		changeSystemBarToWhite();
		setLeftShowOrHidden(true);
		initView();
		mAQ = new AQuery(this);
	}

	private void initTitle(String title) {
		setTopTitle(title, 0, R.drawable.back_bg, new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		}, 0, 0, null, 0);
		setLeftShowOrHidden(true, false);
	}

	private void initView() {
		// TODO Auto-generated method stub
		mContentUtils = new PhoneNumberUtils(this);
		et_phone = (EditText) findViewById(R.id.et_phone);

		sen_bt = (TextView) findViewById(R.id.tv_get_auth_code);
		sen_bt.setOnClickListener(this);

		next = (Button) findViewById(R.id.enter);
		next.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		Intent intent = null;
		switch (v.getId()) {
		case R.id.enter:
			intent = new Intent(this, ResetPwActivity.class);
			startActivity(intent);
			break;
		case R.id.tv_get_auth_code: // 发验证码
//			goRestPw();
			mc=new MyCount(60000, 1000);
			mc.start();
			break;

		default:
			break;
		}
	}

	/**
	 * 获取验证码
	 */
	private void goRestPw() {
		// TODO Auto-generated method stub
		phonnNumber = et_phone.getText().toString().trim();
		if (!mContentUtils.isExist(phonnNumber)) {
			return;
		}

	}

	class MyCount extends CountDownTimer {
		public MyCount(long millisInFuture, long countDownInterval) {
			super(millisInFuture, countDownInterval);
		}

		@Override
		public void onFinish() {
			sen_bt.setText("获取验证码");
			sen_bt.setTextColor(Color.parseColor("#FFFFFF"));
			sen_bt.setEnabled(true);
		}

		@Override
		public void onTick(long millisUntilFinished) {
			sen_bt.setEnabled(false);
			sen_bt.setTextColor(0xFF9D9D9D);
			sen_bt.setText("请等待(" + millisUntilFinished / 1000 + ")秒");
		}
	}
}
